package data;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import android.app.Activity;

/**
 * This class is a wrapper around the ability to check if the account is locked
 * 
 * @author Pooja
 */
public class AccountIsLocked extends DBBooleanTask<Account> {

	/**
	 * This constructor takes in an activity and an account
	 * 
	 * @param activity
	 *            - the activity
	 * @param acct
	 *            - the account to be checked if locked
	 * @throws DBInterfaceError
	 */
	public AccountIsLocked(Activity activity, Account acct)
			throws DBInterfaceError {
		super(activity, acct);
	}

	/**
	 * This task checks if the account is usable
	 * 
	 * @param Account
	 *            account - the account to check
	 * @return true if the account is locked, false otherwise
	 */
	@Override
	protected boolean task(Account account) {
		boolean isLocked = true;
		try {
			PreparedStatement accountLocked = conn
					.prepareStatement("SELECT loginTimes FROM account WHERE locked = true AND accountName = ?");
			accountLocked.setString(1, account.getAccountName());
			ResultSet locked = accountLocked.executeQuery();
			isLocked = locked.next();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return isLocked;
	}

}
